<?php

set_include_path('.' . PATH_SEPARATOR . '..' . PATH_SEPARATOR
        . get_include_path());
require_once('lib/LzTests.php');

$dir        = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$tests      = new LzTests(array('*/_data/*'));
$results    = $tests->run($dir . 'lib') + $tests->run($dir . 'fwk');
$total      = count($results);
$passed     = count(array_filter($results, 'LzTests::passed'));
$failed     = $total - $passed;
?>
<html>
    <title>Lazy tests results</title>
    <style>
        body, td, th { font-family: verdana, sans-serif; font-size: 10pt; text-align:left }
        .failed { color: red }
        .passed { color: green }
        td.numeric { text-align: right }
    </style>
</html>
<body>
    <p>
        <small><?php echo date('Y-m-d H:i:s') ?></small>
    </p>

    <h2>Summary</h2>
    <table class="summary">
        <tr>
            <th class="passed">Passed</th>
            <th class="<?php echo ($failed ? 'failed' : 'passed') ?>">Failed</th>
            <th>Total</th>
        </tr>
        <tr>
            <td align="right" class="passed numeric"><?php echo $passed ?></td>
            <td align="right" class="<?php echo ($failed ? 'failed' : 'passed') ?> numeric">
                    <?php echo $failed ?></td>
            <td align="right" class="numeric"><?php echo $total ?></td>
        </tr>
    </table>

    <h2>Details</h2>
    <table>
        <tr>
            <th>Test</th>
            <th>Duration</th>
            <th>Result</th>
        </tr>
        <?php foreach ($results as $test => $res): ?>
            <tr class="<?php echo ($res['passed'] ? 'passed' : 'failed') ?>">
                <td valign="top">
                    <?php echo substr($test, strlen(dirname(__FILE__))) ?>
                    <?php if (!$res['passed']): ?>
                        <br />
                        <table>
                            <tr>
                                <th>Output</th>
                                <th>Expected</th>
                            </tr>
                            <tr>
                                <td valign="top">
                                    <pre><?php echo $res['output'] ?></pre>
                                </td>
                                <td valign="top">
                                    <pre><?php echo $res['expected'] ?></pre>
                                </td>
                            </tr>
                        </table>
                    <?php endif ?>
                </td>
                <td valign="top"><?php printf('%0.3f', $res['duration']); ?></td>
                <td valign="top"><?php echo ($res['passed'] ? 'Passed' : 'FAILED') ?></td>
            </tr>
        <?php endforeach ?>
    </table>
</body>
</html>

